#include "JDD/classes/AnimationClass.hpp"

namespace JDD
{
AnimationClass::AnimationClass():
    mFrameRect(sf::IntRect(0,0,32,32)),
    mPosition(sf::Vector2i(0,0)),
    mFPS(12),
    mMod(sf::Vector2i(0,0))
{

}
AnimationClass::~AnimationClass()
{

}
void AnimationClass::Update()
{
    if(mClock.GetElapsedTime()>1/(float)mFPS)
    {
        mPosition+=mMod;
        mClock.Reset();
        if(mPosition.x>mSize.x/mFrameRect.GetWidth()-1)
        {
            mPosition.x=0;
        }
        else if(mPosition.x<0)
        {
            mPosition.x=mSize.x/mFrameRect.GetWidth()-1;
        }
        if(mPosition.y>mSize.y/mFrameRect.GetHeight()-1)
        {
            mPosition.y=0;
        }
        else if(mPosition.y<0)
        {
            mPosition.y=mSize.y/mFrameRect.GetHeight()-1;
        }
    }
}
void AnimationClass::SetFPS(int theFPS)
{
    mFPS=theFPS;
}
void AnimationClass::SetRect(sf::IntRect theRect)
{
    mFrameRect=theRect;
}
void AnimationClass::SetPosition(sf::Vector2i thePosition)
{
    mPosition=thePosition;
}
sf::Vector2i AnimationClass::GetPosition()
{
    return mPosition;
}
void AnimationClass::SetMod(sf::Vector2i theMod)
{
    mMod=theMod;
}
void AnimationClass::SetSize(sf::Vector2i theSize)
{
    mSize=theSize;
}
sf::IntRect AnimationClass::GetFrame()
{
    sf::IntRect anFrame=mFrameRect;
    anFrame.Offset(mPosition.x*mFrameRect.GetWidth(),mPosition.y*mFrameRect.GetHeight());
    return anFrame;
}
}
